﻿#include "FITKAbaAbstractLoad.h"
#include "FITKAbaStepManager.h"
#include "FITK_Interface/FITKInterfacePhysics/FITKAbstractFields.h"
#include "FITK_Kernel/FITKCore/FITKDataRepo.h"

namespace Interface {

    bool FITKAbaAbstractLoad::copy(Core::FITKAbstractDataObject* obj)
    {
        FITKAbaAbstractLoad* load = dynamic_cast<FITKAbaAbstractLoad*>(obj);
        if (load == nullptr)
            return false;
        this->_componentID = load->_componentID;
        this->_modelID = load->_modelID;
        this->m_createdStepId = load->m_createdStepId;
        this->m_deactiveStepId = load->m_deactiveStepId;
        this->m_activeState = load->m_activeState;
        this->m_stepManager = load->m_stepManager;
        return true;
    }

    bool FITKAbaAbstractLoad::isValidInCreatedStep()
    {
        if (!this->hasGetStepManager())
            return true;
        FITKAbaAbstractStep* step = m_stepManager->getDataByID(m_createdStepId);
        if (step == nullptr)
            return true;
        if (step->isPerturbation())
            return false;
        return true;
    }

    bool FITKAbaAbstractLoad::hasGetStepManager()
    {
        if (m_stepManager != nullptr)
            return true;
        m_stepManager = this->getStepManager(this);
        if (m_stepManager == nullptr)
            return false;
        return true;
    }

    bool FITKAbaAbstractLoad::getActiveState() const
    {
        return m_activeState;
    }

    void FITKAbaAbstractLoad::setActiveState(bool stat)
    {
        m_activeState = stat;
    }

    void FITKAbaAbstractLoad::setFieldID(const int id)
    {
        _fieldID = id;
    }

    Interface::FITKAbstractFiled* FITKAbaAbstractLoad::getField()
    {
        return FITKDATAREPO->getTDataByID<FITKAbstractFiled>(_fieldID);
    }

}
